Skip to content

blake2: fix size checks in new_with_salt_and_personal - #969

Open
kolinabir wants to merge 3 commits into
RustCrypto:masterfrom
kolinabir:fix/968-blake2-salt-personal
Open

kolinabir wants to merge 3 commits into
RustCrypto:masterfrom
kolinabir:fix/968-blake2-salt-personal

Conversation

@kolinabir

Copy link
Copy Markdown

Closes #968

Blake2{b,s}Mac::new_with_salt_and_personal validated the key against the block size (128/64 bytes) and the salt/persona against a quarter of it (32/16). The actual limits are the key size (64/32) and a quarter of it (16/8). Inputs between the two limits were accepted and then hit the assert!s in new_with_params (and the key_block copy), so Blake2bMac keys of 65..=128 bytes, Blake2sMac keys of 33..=64 bytes, and salt/persona over 16 (b) / 8 (s) bytes panicked instead of returning InvalidLength.

This checks against KeySize (as new_from_slice already does), fixes the doc comment, and adds a CHANGELOG entry.

Testing: added tests in tests/persona.rs for the largest accepted and the first rejected length of key, salt and persona on Blake2bMac512 and Blake2sMac256. They panic before the change and pass after. cargo test -p blake2 (default and --all-features), cargo fmt --check and cargo clippy -p blake2 --all-features --lib --tests are clean.

Copilot AI balanced review requested due to automatic review settings December 4, 2026 05:08

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

blake2: incorrect size checks resulting in panic in new_with_salt_and_personal

2 participants